package com.yenlien.traceyun.breed.controller;

import com.yenlien.traceyun.breed.bean.PreventBean;
import com.yenlien.traceyun.breed.entity.Prevent;
import com.yenlien.traceyun.breed.service.PreventService;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.webase.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by LiuSha on 2020/9/24.
 */
@Api(tags = "养殖防疫管理")
@RestController
@RequestMapping("/prevent")
public class PreventController extends BaseController {
    @Autowired
    private PreventService preventService;

    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    @ApiOperation(value = "列表", notes = "参数示例：{\"page\":\"1\",\"query\":\"BC20200923\"}")
    public Object findByList(@RequestBody Prevent prevent) {
        prevent.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        return buildPage(preventService.findByList(prevent));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "新增或修改", notes = "新增或修改时将整个对象传过来，修改时将要修改的整个对象获取到，把需要修改的字段修改就行")
    public Object save(@RequestBody PreventBean preventBean) {
        preventService.save(preventBean);
        return success("success");
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "查看", notes = "")
    public Object findById(@PathVariable String id) {
        return success(preventService.findById(id));
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "删除", notes = "")
    public Object delete(@PathVariable String id) {
        preventService.delete(id);
        return success("success");
    }
}
